﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace olierFrm.WebFormDev.Plugin
{
    public class HandelURL
    {
        public HandelURL(string url)
        {
            _QueryString = new System.Collections.Specialized.NameValueCollection();
            var us = url.Split('&').ToList();
            us.Remove("");
            foreach (var u in us)
            {
                var uf = u.Split('=');
                _QueryString.Add(uf[0], uf[1]);
            }
        }

        public void CopyQueryString(System.Collections.Specialized.NameValueCollection QueryString)
        {
            if (_QueryString == null) _QueryString = new System.Collections.Specialized.NameValueCollection();
            for (int i = 0; i < QueryString.Count; i++)
            {
                _QueryString.Add(QueryString.Keys[i], QueryString[i]);
            }

        }

        private System.Collections.Specialized.NameValueCollection _QueryString;
        public System.Collections.Specialized.NameValueCollection QueryString
        {
            get
            {
                return _QueryString;
            }
            set
            {
                _QueryString = value;
            }
        }

        public override string ToString()
        {
            string url = "";
            for (int i = 0; i < _QueryString.Count; i++)
            {
                url += _QueryString.Keys[i] + "=" + _QueryString[i] + "&";
            }
            return url.Substring(0, url.Length - 1);
        }
    }
}
